package com.situ.service.impl;
import java.util.*;


import com.situ.dao.BeHistoryDao;
import com.situ.dao.BeOrderuserDao;
import com.situ.entity.BeComment;



import com.situ.dao.BeOrderuserDao;
import com.situ.entity.BeOrderUser_Lw;

import com.situ.dao.BeHistoryDao;
import com.situ.dao.BeOrderuserDao;
import com.situ.entity.BeComment;


import com.situ.dao.BeHistoryDao;
import com.situ.dao.BeOrderuserDao;
import com.situ.entity.BeComment;


import com.situ.entity.BeOrderuser;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.situ.service.BeOrderService;
import com.situ.dao.BeOrderDao;
import com.situ.common.Assist;
import com.situ.entity.BeOrder;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
/**
 * BeOrder的服务接口的实现类
 * 
 * @author 
 *
 */
@Service
public class BeOrderServiceImpl implements BeOrderService {
	private final Logger LOG = LogManager.getLogger(this.getClass());

	@Autowired
	private BeOrderDao beOrderDao;

	@Autowired
	private BeOrderuserDao beOrderuserDao;
	@Autowired
	private BeHistoryDao beHistoryDao;

	// TODO 当你看到这个方法时你应该创建一个工具类做通用的方法,定义自己的返回格式化
	private static final int C200 = 200;
	private static final int C412 = 412;

	public String resultFormat(int code, Object data) {
		JSONObject result = new JSONObject();
		result.put("code", code);
		if (data != null) {
			result.put("data", data);
		}
		return result.toJSONString();
	}

	@Override
	public List<BeOrder> find(BeOrder value) {
		//TODO这里可以做通过Assist做添加查询
		List<BeOrder> result = beOrderDao.selectBeOrder(null);
		if (LOG.isDebugEnabled()) {
			LOG.debug("执行获取BeOrder数据集-->结果:", result);
		}
		return result;
	}

	@Override
	public BeOrder findOne(String id) {
		if (id == null) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("执行通过BeOrder的id获得BeOrder对象-->失败:id不能为空");
			}
			return null;
		}
		BeOrder result = beOrderDao.selectBeOrderById(id);
		if (LOG.isDebugEnabled()) {
			LOG.debug("执行通过BeOrder的id获得BeOrder对象-->结果:", result);
		}
		return result;
	}
	//根据类型查询
	@Override
	public List<BeOrder> findType(int stepId){
		List<BeOrder> belist=beOrderDao.selectBeOrderByType(stepId);
		return belist;
	}
	//高级查询
	@Override
	public List<BeOrder> findBeOrder(BeOrder beo){
		List<BeOrder> bli=beOrderDao.gjcxBeOrder(beo);
		return bli;
	}

	@Override
	public  List<BeOrderuser> selectKh(String orderNo){
		List<BeOrderuser> uselist=beOrderDao.selectClient(orderNo);
		return uselist;
	};
	@Override
	public String saveNotNull(BeOrder value) {
		if (value == null) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("执行将BeOrder中属性值不为null的数据保存到数据库-->失败:对象不能为空");
			}
			return resultFormat(C412, null);
		}
		int result = beOrderDao.insertNotNullBeOrder(value);
		if (LOG.isDebugEnabled()) {
			LOG.debug("执行将BeOrder中属性值不为null的数据保存到数据库-->结果:", result);
		}
		return resultFormat(C200, result);
	}

	@Override
	public String updateNotNullById(BeOrder value) {
		if (value == null) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("执行通过BeOrder的id更新BeOrder中属性不为null的数据-->失败:对象为null");
			}
			return resultFormat(C412, null);
		}
		int result = beOrderDao.updateNotNullBeOrderById(value);
		if (LOG.isDebugEnabled()) {
			LOG.debug("执行通过BeOrder的id更新BeOrder中属性不为null的数据-->结果:", result);
		}
		return resultFormat(C200, result);
	}

	@Override
	public String deleteById(String id) {
		if (id == null) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("执行通过BeOrder的id删除BeOrder-->失败:id不能为空");
			}
			return resultFormat(C412, null);
		}
		int result = beOrderDao.deleteBeOrderById(id);
		if (LOG.isDebugEnabled()) {
			LOG.debug("执行通过BeOrder的id删除BeOrder-->结果:", result);
		}
		return resultFormat(C200, result);
	}

	public String findDate(int noq) {
		return beOrderDao.findDate(noq);
	}

	public int updateW(BeOrder beOrder) {
		return beOrderDao.updateW(beOrder);
	}

	public List<Map> selectStep() {
		return beOrderDao.selectStep();
	}

	public BeOrderuser old(String UserNo) {
		return beOrderDao.old(UserNo);
	}

	public List<BeOrderuser> beuser(String value) {
		return beOrderDao.beuser(value);
	}

	public List<Map> mes(String value) {
		return beOrderDao.mes(value);
	}

	public Map gonglook(String value) {
		return beOrderDao.gonglook(value);
	}

	public List<BeComment> fmes(String value) {
		return beOrderDao.fmes(value);
	}


	public int upcomment(BeComment comm){


		return beOrderDao.upcomment(comm);
	}

	public  BeComment addcomment(BeComment comm){
		 beOrderDao.addcomm(comm);
		return null;
	}

	public void decomm(BeComment beComment){
		beOrderDao.decomm(beComment);
	}

	//工单报表的高级查询
	public List<Map> CxCollect(BeOrder enti){
		return beOrderDao.cxCharge(enti);
	}

	@Override
	@Transactional
	public void updateShi(BeOrder ore, BeOrderUser_Lw orduse) {
		beOrderDao.updateNotNullBeOrderById(ore);
		for (BeOrderuser b : orduse.getList()){
			beOrderuserDao.updateNotNullBeOrderuserById(b);
		}
	}





}